package main

import (
	"context"
	"fmt"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
	"log"
)

func logErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	config, err := clientcmd.BuildConfigFromFlags("", ".kubeconfig")
	config.Insecure = true
	logErr(err)
	clientset, err := kubernetes.NewForConfig(config)
	logErr(err)
	ns := "istio-system"
	pods, err := clientset.CoreV1().Pods(ns).List(context.Background(), metav1.ListOptions{})
	logErr(err)
	for _, pod := range pods.Items {
		for k, v := range pod.Labels {
			fmt.Println(pod.Name, k, v)
		}
	}
}
